
package timeitj.ejb;

import java.util.List;
import javax.annotation.security.DeclareRoles;
import javax.annotation.security.PermitAll;
import javax.annotation.security.RolesAllowed;
import javax.ejb.Remote;
import timeitj.persistence.Invitation;
import timeitj.persistence.Participance;
import timeitj.persistence.Person;
import timeitj.persistence.Project;
import timeitj.util.exceptions.InvitationFailedException;

/**
 * This is the business interface for SessionFacade enterprise bean.
 */
@DeclareRoles({"USERS","ADMINS"})
@Remote
public interface SessionFacade {
    
    /**
     * Gets the currently logged in user in this session.
     * @return The curretnly logged in user as instance
     * of timeitj.persistence.Person
     */
    @RolesAllowed("USERS")
    public Person getCurrentUser();
    
    /**
     * Registers the given person in the system.
     * @param person The person to register
     */
    @PermitAll
    public Person createPerson(Person person);
    
    /**
     * Creates a new project.
     */
    @RolesAllowed("USERS")
    public Project createProject(Project project);
    
    /**
     * Update the given project in the database
     * @param The project to synchronize the DB
     * @return Returns the given Project
     */
    @RolesAllowed("USERS")
    public Project updateProject(Project project);
    
    /**
     * Deletes a project.
     * @param The project to delete.
     */
    @RolesAllowed("USERS")
    public void deleteProject(Project project);
    
    /**
     * Returns the projects for the given owner.
     * @param owner The person who owns the projects
     * @return Returns the owners projects in an array
     * of timeitj.persistence.Project
     */
    @RolesAllowed("USERS")
    public List<Project> getProjectsByOwner(Person owner);
    
    @RolesAllowed("USERS")
    public List<Participance> getParticipancesByProject(Project project);
    
    @RolesAllowed("USERS")
    public void deleteParticipance(Participance participance);
    
    @RolesAllowed("USERS")
    public Participance createParticipance(Participance participance);
    
    @RolesAllowed("USERS")
    public List<Participance> getParticipancesByPerson(Person person);
    
    @RolesAllowed("USERS")
    public List<Person> getAllUsers();
    
    /**
     * Invites the given Person to the given Project
     * @param person The Person to invite
     * @param project The Project to invite it to
     * @return returns an Invitation-Object
     */
    @RolesAllowed("USERS")
    public Invitation invitePerson(Person invitee, Project project) throws InvitationFailedException;
}
